<?php

namespace app\admin\controller;
class Weblog extends base
{

    //前置方法
    protected $beforeActionList = [
        'map'  =>  ['only'=>'index'],
    ];

    /**
     * 搜索
     */
    protected function map(){
        if ($this->request->isGet()) {
            $data = $this->request->param();
            $this->datas = array();
            if (!empty($data['start_time']) && !empty($data['end_time']) && (strtotime($data['start_time']) < strtotime($data['end_time']))) {
                $this->datas ['create_time'] = [
                    ['>', strtotime($data['start_time'])],
                    ['<', strtotime($data['end_time'])]
                ];
            }

            if (isset($data['name']) && !empty($data['name'])) {
                $this->datas ['name'] = $data['name'];
            }
            if (isset($data['controller']) && !empty($data['controller'])) {
                $this->datas ['controller'] = $data['controller'];
            }
            if (isset($data['action']) && !empty($data['action'])) {
                $this->datas ['action']  =  $data['action'];
            }
        }
    }

    /**
     * 详情
     */
    public function detail()
    {
        $id = $this->request->param('id');
        if (!$id) {
            throw new Exception('缺少必要参数ID');
        }

        // 条件
        $map['id'] = $id;
        // 查询
        $list =model('Weblog')
            ->where($map)->find();


        $this->view->assign('vo', $list);

        return $this->view->fetch();
    }

}
